package controllers

import (
	"golang-websocket-service/tools"
	"log"

	"github.com/gin-gonic/gin"
)

/*
 +----------------------------------------------------------------------
 + Title        : BroadcastController
 + Author       : huwl
 + Version      : 2.0.0
 + Initial-Time : 2024-11-23
 + Last-time    : 这个文件最后修改的时间 + 修改人的名称
 + Desc         : 广播控制器
 +----------------------------------------------------------------------
*/

type BroadcastController struct {
	BaseController
}

/**
 * 广播
 *
 * @return json
 * @author huwl
 */
func (control *BroadcastController) Index(ctx *gin.Context) {
	log.Println(" ----------------- 广播 ----------------- ")
	fromUid := ctx.DefaultQuery("from_uid", "0")
	log.Println("fromUid =", fromUid)

	// HandleRequest将http请求升级为websocket连接，并将其分派给melody实例处理
	tools.WsSrv.WebsocketSrv.HandleRequest(ctx.Writer, ctx.Request)
}
